//

// (  )
//

package com.tools.acceleratecore.xlib.tool.impl;

import android.content.Context;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.text.TextUtils;
import com.tools.acceleratecore.xlib.XLibFactory;
import com.tools.acceleratecore.xlib.tool.intf.IWakeLockTool;

public class WakeLockTool implements IWakeLockTool {
    private Context mContext = null;
    private WakeLock mWakeLock = null;

    public WakeLockTool() {
        this.mContext = XLibFactory.getApplication();
        this._init();
    }

    private void _init() {
    }

    public boolean setWakeLock(int nWakeLockType, String strWakeLockName) {
        if (TextUtils.isEmpty(strWakeLockName)) {
            return false;
        } else {
            PowerManager pm = (PowerManager)this.mContext.getSystemService("power");
            this.mWakeLock = pm.newWakeLock(nWakeLockType, strWakeLockName);
            return this.mWakeLock != null;
        }
    }

    public void acquire() {
        this.mWakeLock.acquire();
    }

    public void release() {
        if (this.mWakeLock.isHeld()) {
            this.mWakeLock.release();
        }
    }
}
